var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, n, i) {
    var o, a = arguments.length, s = a < 3 ? t : null === i ? i = Object.getOwnPropertyDescriptor(t, n) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, n, i); else for (var r = e.length - 1; 0 <= r; r--) (o = e[r]) && (s = (a < 3 ? o(s) : 3 < a ? o(t, n, s) : o(t, n)) || s);
    return 3 < a && s && Object.defineProperty(t, n, s), s;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("PopItemView"), s = e("Global"), c = e("PersonView"), l = e("LevelView"), d = e("AudioManager"), u = e("GameConfig"), p = e("GameData"), h = e("DataManager"), f = e("WebManager"), g = e("LoadManager"), m = e("UIManager"), y = e("AdManager"), v = cc._decorator, w = v.ccclass, b = v.property, P = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.personIdx = 11, e.rank = null, e.reward = null, e.levelView = null, e.titleSprite = null, 
        e.timeLabel = null, e.personView = null, e.btns = null, e.condition = null, e.conditionList = [], 
        e.authBtn = null, e;
    }
    return i(e, t), e.prototype.onEnable = function() {}, e.prototype.onDisable = function() {
        t.prototype.onDisable.call(this), this.hideAuth();
    }, e.prototype.onClickRewardShow = function() {
        d.default.getInstance().playAudio("按钮2"), f.default.getInstance().sentLog("点击" + this.viewname + "界面显示奖励按键"), 
        this.showReward();
    }, e.prototype.onClickRewardHide = function() {
        d.default.getInstance().playAudio("按钮2"), f.default.getInstance().sentLog("点击" + this.viewname + "界面隐藏奖励按键"), 
        this.hideReward();
    }, e.prototype.init = function() {
        this.initLevel(), this.initSkin(), this.initCondition(), this.initAuth(), this.initEggs();
    }, e.prototype.callback = function() {
        isNaN(this.personIdx) || p.GD.addSkin(this.personIdx) && (p.GD.personIdx < this.personIdx && (p.GD.personIdx = this.personIdx), 
        h.default.getInstance().upload({
            json: !0,
            local: !0,
            skin: this.personIdx
        }), this.showAlready(), m.default.getInstance().loadPopPnl("reward", {
            type: s.RewardType.SKIN,
            idx: this.personIdx
        }));
    }, e.prototype.initLevel = function() {
        this.levelView.refresh(p.GD.level), this.timeLabel.string = "距离赛季结束\n还有" + Math.ceil(s.G.seasonTime / 864e5) + "天", 
        g.default.getInstance().loadSpriteFrame({
            url: "image/ui/S" + s.G.seasoncount + "赛季@2x",
            sprite: this.titleSprite
        });
    }, e.prototype.initSkin = function() {
        this.personIdx = s.G.seasonPersonIdx, this.personView.init(this.personIdx);
    }, e.prototype.initCondition = function() {
        var e, t;
        p.GD.hasSkin(this.personIdx) ? this.showAlready() : (e = 0, t = u.GC.seasonConditionConfig, 
        s.G.getRank(p.GD.level).r >= t.r && (e += 1), p.GD.winNum >= t.n && (e += 2), cc.log("GD.level", p.GD.level, "GD.winNum", p.GD.winNum), 
        3 == e ? (this.myButton.init(this.text), this.showBtn()) : this.showCondition(e));
    }, e.prototype.initAuth = function() {
        var e, t, n = this;
        try {
            p.GD.playerData.nickname || p.GD.playerData.icon || (s.G.isAuth = !1), s.G.isAuth ? console.log("playerDate:", JSON.stringify(p.GD.playerData)) : GA.isWeChat() || GA.isQQ() ? (e = GA.PA.getSystemInfoSync().screenWidth / cc.view.getVisibleSize().width, 
            t = cc.v2(this.node.convertToNodeSpaceAR(this.rank.convertToWorldSpaceAR(cc.Vec2.ZERO))), 
            this.authBtn = GA.PA.createUserInfoButton({
                type: "text",
                text: "",
                image: "",
                style: {
                    left: (GA.PA.getSystemInfoSync().screenWidth + (2 * t.x - this.rank.width) * e) / 2,
                    top: (GA.PA.getSystemInfoSync().screenHeight - (2 * t.y + this.rank.height) * e) / 2,
                    width: this.rank.width * e,
                    height: this.rank.height * e,
                    backgroundColor: "",
                    borderColor: "",
                    borderWidth: 0,
                    borderRadius: 4,
                    color: "",
                    textAlign: "center",
                    fontSize: 16,
                    lineHeight: 40
                },
                withCredentials: !1
            }), this.authBtn && this.authBtn.onTap(function(e) {
                e.userInfo && (e = e.userInfo, p.GD.playerData.nickname = e.nickName, p.GD.playerData.icon = e.avatarUrl, 
                p.GD.playerData.sex = e.gender, h.default.getInstance().save(), s.G.isAuth = !0, 
                n.authBtn && n.authBtn.hide(), f.default.getInstance().saveRank({
                    data: {
                        userid: GA.Info.uid,
                        level: p.GD.level,
                        nickname: e.nickName,
                        headicon: e.avatarUrl
                    }
                }));
            })) : GA.isByteDance() ? this.rank.on(cc.Node.EventType.TOUCH_START, function() {
                s.G.isAuth || GA.PA.getSetting({
                    success: function(e) {
                        console.log("getSetting", e), e.authSetting["scope.userInfo"] ? GA.PA.getUserInfo({
                            withCredentials: !1,
                            success: function(e) {
                                console.log("获取用户信息成功", e);
                                e = e.userInfo;
                                p.GD.playerData.nickname = e.nickName, p.GD.playerData.icon = e.avatarUrl, p.GD.playerData.sex = e.gender, 
                                h.default.getInstance().save(), s.G.isAuth = !0, f.default.getInstance().saveRank({
                                    data: {
                                        userid: GA.Info.uid,
                                        level: p.GD.level,
                                        nickname: e.nickName,
                                        headicon: e.avatarUrl
                                    }
                                }), f.default.getInstance().sentLog("点击首页视频排行榜"), m.default.getInstance().loadPnl("video", null, function() {
                                    y.default.getInstance().hideAllBanner();
                                });
                            },
                            fail: function(e) {
                                console.log("获取用户信息失败", e);
                            }
                        }) : GA.PA.authorize({
                            scope: "scope.userInfo",
                            success: function(e) {
                                console.log("授权成功", e), GA.PA.getUserInfo({
                                    withCredentials: !1,
                                    success: function(e) {
                                        console.log("获取用户信息成功", e);
                                        e = e.userInfo;
                                        p.GD.playerData.nickname = e.nickName, p.GD.playerData.icon = e.avatarUrl, p.GD.playerData.sex = e.gender, 
                                        h.default.getInstance().save(), s.G.isAuth = !0, f.default.getInstance().saveRank({
                                            data: {
                                                userid: GA.Info.uid,
                                                level: p.GD.level,
                                                nickname: e.nickName,
                                                headicon: e.avatarUrl
                                            }
                                        }), f.default.getInstance().sentLog("点击首页视频排行榜"), m.default.getInstance().loadPnl("video", null, function() {
                                            y.default.getInstance().hideAllBanner();
                                        });
                                    },
                                    fail: function(e) {
                                        console.log("获取用户信息失败", e);
                                    }
                                });
                            },
                            fail: function(e) {
                                var t;
                                console.log("授权失败", e), null === (e = null === (t = GA.PA) || void 0 === t ? void 0 : t.showModal) || void 0 === e || e.call(t, {
                                    title: "提示",
                                    content: "为了更好展示你的信息，需要你授权",
                                    success: function(e) {
                                        e.confirm ? GA.PA.openSetting({
                                            succes: function(e) {
                                                console.log("openSetting", e), e.authSetting["scope.userInfo"] && GA.PA.getUserInfo({
                                                    withCredentials: !1,
                                                    success: function(e) {
                                                        console.log("获取用户信息成功", e);
                                                        e = e.userInfo;
                                                        p.GD.playerData.nickname = e.nickName, p.GD.playerData.icon = e.avatarUrl, p.GD.playerData.sex = e.gender, 
                                                        h.default.getInstance().save(), s.G.isAuth = !0, f.default.getInstance().saveRank({
                                                            data: {
                                                                userid: GA.Info.uid,
                                                                level: p.GD.level,
                                                                nickname: e.nickName,
                                                                headicon: e.avatarUrl
                                                            }
                                                        }), f.default.getInstance().sentLog("点击首页视频排行榜"), m.default.getInstance().loadPnl("video", null, function() {
                                                            y.default.getInstance().hideAllBanner();
                                                        });
                                                    },
                                                    fail: function(e) {
                                                        console.log("获取用户信息失败", e);
                                                    }
                                                });
                                            }
                                        }) : s.G.isAuth = !0;
                                    }
                                });
                            }
                        });
                    }
                });
            }, this) : GA.isPlatform(GA.Platform.UCMiniGame) && this.rank.on(cc.Node.EventType.TOUCH_START, function() {
                s.G.isAuth || GA.PA.authorize({
                    scope: "userInfo",
                    success: function() {
                        GA.PA.getUserInfo({
                            withCredentials: !1,
                            success: function(e) {
                                console.log("getUserInfo success", e), p.GD.playerData.nickname = e.nickname, p.GD.playerData.icon = e.avatar_url, 
                                h.default.getInstance().save(), s.G.isAuth = !0, n.rank.off(cc.Node.EventType.TOUCH_START), 
                                f.default.getInstance().saveRank({
                                    data: {
                                        userid: GA.Info.uid,
                                        level: p.GD.level,
                                        nickname: p.GD.playerData.nickname,
                                        headicon: p.GD.playerData.icon
                                    }
                                });
                            }
                        });
                    }
                });
            }, this);
        } catch (e) {}
    }, e.prototype.initEggs = function() {}, e.prototype.showCondition = function(e) {
        console.log("winNum", p.GD.winNum), this.btns.active = !1, this.condition.active = !0, 
        this.conditionList = this.condition.getComponentsInChildren(cc.Label);
        var t = u.GC.seasonConditionConfig;
        !isNaN(t.r) && t.r < s.G.levelList.length && 0 < this.conditionList.length && (this.conditionList[0].string = s.G.levelList[t.r] + "以上段位\n" + (1 == e ? "完成" : "未完成")), 
        !isNaN(t.n) && 1 < this.conditionList.length && (this.conditionList[1].string = "胜利" + t.n + "场\n" + (2 == e ? "完成" : p.GD.winNum + "/" + t.n));
    }, e.prototype.showBtn = function() {
        s.G.platform == s.Platform.XiaoDu ? this.callback() : (this.btns.active = !0, this.condition.active = !1);
    }, e.prototype.showAlready = function() {
        this.btns.getComponentsInChildren(cc.Button).forEach(function(e) {
            return e.interactable = !1;
        });
    }, e.prototype.showReward = function() {
        this.rank.active = !1, this.reward.active = !0, this.hideAuth();
    }, e.prototype.hideReward = function() {
        this.rank.active = !0, this.reward.active = !1, this.showAuth();
    }, e.prototype.showAuth = function() {
        !s.G.isAuth && this.authBtn && this.authBtn.show();
    }, e.prototype.hideAuth = function() {
        this.authBtn && this.authBtn.hide();
    }, e.prototype.hidePnl = function() {
        t.prototype.hidePnl.call(this), m.default.getInstance().showPnl("start");
    }, a([ b ], e.prototype, "personIdx", void 0), a([ b(cc.Node) ], e.prototype, "rank", void 0), 
    a([ b(cc.Node) ], e.prototype, "reward", void 0), a([ b(l.default) ], e.prototype, "levelView", void 0), 
    a([ b(cc.Sprite) ], e.prototype, "titleSprite", void 0), a([ b(cc.Label) ], e.prototype, "timeLabel", void 0), 
    a([ b(c.default) ], e.prototype, "personView", void 0), a([ b(cc.Node) ], e.prototype, "btns", void 0), 
    a([ b(cc.Node) ], e.prototype, "condition", void 0), a([ w ], e);
}(r.default);

n.default = P;